<template>
  <div  class="p-[10px] relative">
    <div>待新闻发布({{ releaseList?.length }})</div>
    <div class="text-sm">
        <RelaeseItem v-for="item in releaseList" :key="'item.id'"@removeData="handleRemove" :data="item"/>
    </div>
    <div class="absolute top-[425px]">
        <el-button class=" w-full" type="primary" v-role="'admin'" @click="router.push({name:'newspublish'})">发布设置</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import {onMounted,ref} from 'vue'
import {ElMessage} from "element-plus"
import RelaeseItem  from '@/components/ReleaseItem.vue'
import {getReleaseList ,updateNews} from '@/api/newsApi'
import { useRouter } from 'vue-router'

const releaseList=ref()
const router = useRouter()
const handleRemove = async (id: number) => {
    const res = await updateNews({ id, isSelect: 0 })
    if (res.code == 200) {
        ElMessage.success('移除成功')
        releaseList.value = releaseList.value.filter((it:Record<string,unknown>) =>it.id !==id)
    }
    return res 
}
const refesh=async ()=>{
    const res =await getReleaseList() as { data: { list: [] } }
    releaseList.value=res.data.list
}

onMounted(async()=>{
    const res=await getReleaseList()
    releaseList.value=res.data.list
})

defineExpose({
    releaseList,
    refesh
})

</script>

<style lang="scss" scoped>

</style>
